package jacob;

import java.util.ArrayList;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.monster.EntityCaveSpider;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityPigZombie;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntityWitch;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.passive.EntityCow;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;

public class Spawnerjacob extends Block 
{


	public void onEntityWalking(World par1World, int par2, int par3, int par4, Entity par5Entity)
    {
        try 
        {
                EntityPlayer player = (EntityPlayer)par5Entity;
        //player.addPotionEffect(new PotionEffect(Potion.jump.id, 50, 20));
          //player.setVelocity((player.posX - player.lastTickPosX)*20, 21000000, (player.posZ - player.lastTickPosZ)*20);
                player.setVelocity((player.posX - player.lastTickPosX)*20, 20, (player.posZ - player.lastTickPosZ)*20);
        }
        catch(Exception e)
        {
                
        }
        
    } 
	public Spawnerjacob(int par1, Material par2Material) 
	{
		super(par1, par2Material);
		//this.slipperiness = 15f;
		this.setCreativeTab(CreativeTabs.tabBlock);
	}
	public boolean isOpaqueCube()
	{
		return false;
	}
	
	public void registerIcons(IconRegister iconReg)
	{
	      blockIcon = iconReg.registerIcon("iDTechModBase:Spawnerjacob");
	        
	}
	 

	public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
	{
		
		activated = true;//              x    y     z
		par1World.scheduleBlockUpdate(par2, par3, par4, blockID, 1);
	    return false;
	   
	}
	public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 
	{
		if (activated)
		{
			if (maxNumCritters > allcreatures.size())
			{
				if (maxNumCreeper > NumCreeperCreated)
				{
					EntityCreeper Creeper = new EntityCreeper(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Creeper.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Creeper);
					NumCreeperCreated++;
					allcreatures.add(Creeper);
					
				}
				else if (maxNumSpider > NumSpiderCreated)
				{
					EntityCaveSpider Spider = new EntityCaveSpider(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Spider.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Spider);
					NumSpiderCreated++;
					allcreatures.add(Spider);
					
				}
				else if (maxNumWitch > NumWitchCreated)
				{
					EntityWitch Spider = new EntityWitch(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Spider.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Spider);
					NumWitchCreated++;
					allcreatures.add(Spider);
					
				}
				else if (maxNumZombie > NumZombieCreated)
				{
					EntityZombie Spider = new EntityZombie(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Spider.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Spider);
					ItemStack weapon = new ItemStack(Item.swordIron);
					weapon.addEnchantment(Enchantment.sharpness, 2);
					Spider.setCurrentItemOrArmor(0, weapon);
					//1 is boots
					//4 is helm
					//3 chestplate
					//2 leggings 
					//0 is sword
				    ItemStack armor2 = new ItemStack(ItemArmor.bootsChain);
				    armor2.addEnchantment(Enchantment.protection, 5);
					Spider.setCurrentItemOrArmor(1, armor2);
					ItemStack armor = new ItemStack(ItemArmor.plateChain);
					armor.addEnchantment(Enchantment.thorns, 10);
					Spider.setCurrentItemOrArmor(3, armor);
					ItemStack armor3 = new ItemStack(ItemArmor.legsChain);
					armor3.addEnchantment(Enchantment.projectileProtection, 3);
					Spider.setCurrentItemOrArmor(2, armor3);
					ItemStack armor4 = new ItemStack(ItemArmor.helmetChain);
					armor4.addEnchantment(Enchantment.featherFalling, 4);
					Spider.setCurrentItemOrArmor(4, armor4);
					
					NumZombieCreated++;
					allcreatures.add(Spider);
					
				}
				else if (maxNumPigmen > NumPigmenCreated)
				{
					EntityPigZombie Spider = new EntityPigZombie(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Spider.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Spider);
					ItemStack goldsword = new ItemStack(Item.swordGold);
					goldsword.addEnchantment(Enchantment.knockback, 2);
					Spider.setCurrentItemOrArmor(0, goldsword);
					ItemStack goldchest = new ItemStack(ItemArmor.plateGold);
					goldchest.addEnchantment(Enchantment.protection, 2);
					Spider.setCurrentItemOrArmor(3, goldchest);
					ItemStack goldlegs = new ItemStack(ItemArmor.legsGold);
					goldlegs.addEnchantment(Enchantment.protection, 2);
					Spider.setCurrentItemOrArmor(2, goldlegs);
					ItemStack goldboots = new ItemStack(ItemArmor.bootsGold);
					goldboots.addEnchantment(Enchantment.projectileProtection, 2);
					Spider.setCurrentItemOrArmor(1, goldboots);
					ItemStack goldhelmet = new ItemStack(ItemArmor.helmetGold);
					goldhelmet.addEnchantment(Enchantment.projectileProtection, 2);
					Spider.setCurrentItemOrArmor(4, goldhelmet);
					NumPigmenCreated++;
					allcreatures.add(Spider);
					
				}
				else if (maxNumZombiechild > NumZombiechildCreated)
				{
					EntityZombie Spider = new EntityZombie(par1World);
					Vec3 Vec = util.placeInRandomDir(par2, par3, par4, 2);
					Spider.setPosition(Vec.xCoord, Vec.yCoord, Vec.zCoord);
					par1World.spawnEntityInWorld(Spider);
					ItemStack weapon = new ItemStack(Item.swordDiamond);
					weapon.addEnchantment(Enchantment.sharpness, 1);
					Spider.setCurrentItemOrArmor(0, weapon);
				    ItemStack armor2 = new ItemStack(ItemArmor.bootsIron);
				    armor2.addEnchantment(Enchantment.protection, 1);
					Spider.setCurrentItemOrArmor(1, armor2);
					ItemStack armor = new ItemStack(ItemArmor.plateIron);
					armor.addEnchantment(Enchantment.thorns, 1);
					Spider.setCurrentItemOrArmor(3, armor);
					ItemStack armor3 = new ItemStack(ItemArmor.legsIron);
					armor3.addEnchantment(Enchantment.projectileProtection, 1);
					Spider.setCurrentItemOrArmor(2, armor3);
					ItemStack armor4 = new ItemStack(ItemArmor.helmetIron);
					armor4.addEnchantment(Enchantment.featherFalling, 1);
					Spider.setCurrentItemOrArmor(4, armor4);
					Spider.setChild(true);
					Spider.setEntityHealth(20);
					Spider.setSprinting(true);
					Spider.setSneaking(true);
					NumZombiechildCreated++;
					allcreatures.add(Spider);
					
				}
			}
			par1World.scheduleBlockUpdate(par2, par3, par4, blockID, 60);
		}	
	}
	private boolean activated = false;
	private int maxNumCritters = 110;
	private int maxNumWitch = 10;
	private int maxNumSpider = 15;
	private int maxNumCreeper = 10;
	private int maxNumZombie = 25;
	private int maxNumPigmen= 20;
	private int maxNumZombiechild = 30;
	private int NumZombiechildCreated = 0;
	private int NumPigmenCreated = 0;
	private int NumZombieCreated = 0;
	private int NumCreeperCreated = 0;
	private int NumWitchCreated = 0;
	private int NumSpiderCreated = 0;
	private ArrayList<EntityLiving> allcreatures = new ArrayList<EntityLiving>();
}